//
//  NSString+fileSize.m
//  新浪微博
//
//  Created by qianfeng on 16/2/28.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "NSString+fileSize.h"

@implementation NSString (fileSize)
-(long long)fileSize
{
    NSFileManager *fm =[NSFileManager defaultManager];
    BOOL isDirectory;
    BOOL isExist = [fm fileExistsAtPath:self isDirectory:&isDirectory];
    if (isExist) {
        if (isDirectory) {
            NSArray *array = [fm contentsOfDirectoryAtPath:self error:nil];
            long long fileSize=0 ;
            for (NSString *path in array) {
                NSString *filePath =[self stringByAppendingPathComponent:path];
                fileSize+=  [filePath fileSize];
            }
            return fileSize;
        }
        else
        {
            NSDictionary *attri = [fm attributesOfItemAtPath:self error:nil];
            return [attri[NSFileSize] longLongValue];
        }
    }
    else
    {
        return 0;
    }
}
@end
